Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(formatNumber): allow negative fraction size #13913

Closed
wants to merge 1 commit into from

Conversation

jbedard
Copy link
Collaborator

@jbedard jbedard commented Jan 31, 2016

This worked before 6a0686d. The other option would be to not support this and just convert fractionSize < 0 to 0.

This solution could probably be improved though...

} else {
// We rounded to zero so reset the parsedNumber
parsedNumber.i = 1;
digits.length = roundAt = fractionSize + 1;
for (var i=0; i < roundAt; i++) digits[i] = 0;
digits.length = Math.max(1, roundAt = fractionSize + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, fractionSize + 1 can never be > 1, because:

fractionSize + 1 > 1 <=>
fractionSize > 0     <=>
fractionSize + parsedNumber.i > 0 (because `parsedNumber.i > 0`) <=>
roundedAt > 0 (on line 220) <=>
We wouldn't be on this branch of the if-else block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm...it seems that parsedNumber.i can be < 1, so ignore the above :)

@gkalpak
Copy link
Member

gkalpak commented Feb 1, 2016

Other than the 2 issues pointed in the comments, it LGTM.

@Narretz Narretz added this to the Backlog milestone Feb 1, 2016
@jbedard jbedard force-pushed the negative-precision branch 2 times, most recently from 43d5480 to eb38484 Compare February 4, 2016 06:17
@jbedard
Copy link
Collaborator Author

jbedard commented Feb 4, 2016

Added tests and your fixes. Thanks for showing the exact fixes!

digits.splice(Math.max(parsedNumber.i, roundAt));

// Set non-fractional digits beyond `roundAt` to 0
for (var j=roundAt; j < digits.length; j++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that JSCS doesn't complain about no space around = (I thought it would) :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated! Line 237 also updated, note that that one had no spaces before this commit as well...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't mean you had to change it necessarily - I was just surprised with JSCS.
But look how much better it looks now 😛

@gkalpak
Copy link
Member

gkalpak commented Feb 4, 2016

LGTM

@jbedard jbedard force-pushed the negative-precision branch from eb38484 to aeb0d01 Compare February 4, 2016 08:54
@petebacondarwin petebacondarwin modified the milestones: 1.5.1, Backlog Feb 4, 2016
@Narretz
Copy link
Contributor

Narretz commented Feb 17, 2016

@gkalpak do you want to merge?

@gkalpak
Copy link
Member

gkalpak commented Feb 17, 2016

@Narretz, on it ! Thx for the reminder 😃

@gkalpak gkalpak closed this in 735be18 Feb 17, 2016
gkalpak pushed a commit that referenced this pull request Feb 17, 2016
@gkalpak
Copy link
Member

gkalpak commented Feb 17, 2016

Backported to v1.5.x as e046c17.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants